﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YX.Properties;

namespace YX
{
    class EnemyPlane:FatherPlane
    {
        private static Image image0 = Resources.enemy0;
        private static Image image1 = Resources.enemy1;
        private static Image image2 = Resources.enemy2;
        public EnemyPlane(int x, int y, int type) : base(x, y, imageType(type), speedType(type), LifeType(type), Direction.Down)
        {
            this.EnemyType = type;
        }
        public int EnemyType
        {
            get;
            set;
        }

        public static Image imageType(int type)
        {
            switch(type)
            {
                case 0:
                    return image0;
                    case 1:
                    return image1;
                    case 2:
                    return image2;
            }
            return null;
        }

        public static int speedType(int type)
        {
            switch(type)
            {
                case 0:
                    return 5;
                    case 1:
                    return 6;
                    case 2:
                    return 7;
            }
            return 0;
        }

        public static int LifeType(int type)
        {
            switch (type)
            {
                case 0:
                    return 1;
                case 1:
                    return 2;
                case 2:
                    return 3;
            }
            return 0;
        }

        public override void Draw(Graphics g)
        {
            Move();
            switch(EnemyType)
            {
                case 0:
                    g.DrawImage(image0,this.X,this.Y);
                    break;
                case 1:
                     g.DrawImage(image1,this.X,this.Y);
                    break;
                case 2:
                     g.DrawImage(image2,this.X,this.Y);
                    break;
            }
        }

        Random ran = new Random();
        public override void Move()
        {
            switch(this.Dir)
            {
                case Direction.Up:
                    this.Y -= Speed;
                    break;
                case Direction.Down:
                    this.Y += Speed;
                    break;
                case Direction.Left:
                    this.X -= Speed;
                    break;
                case Direction.Right:
                    this.X += Speed;
                    break;
            }

            if (this.Y >= 700)
            {
                this.Y = 950;
                SingleClass.GetSingle.RemoveClass(this);
            }

            
            if(this.Y>=100 && this.EnemyType==0)
            {
                if(this.X>0 && this.X<=204)
                {
                    this.X += ran.Next(0, 100);
                }
                else
                {
                    this.X -= ran.Next(0, 100);
                }
            }
            else if(this.EnemyType!=0)
            {
                this.Speed += 1;
            }

            if(ran.Next(0,100)>70)
            {
                Fire();
            }
        }

        public void Fire()
        {
            SingleClass.GetSingle.AddBaseClase(new EnemyBullt(this, 20, 1));
        }

        public override void It_Over()
        {
            if(this.Life<=0)
            {
                SingleClass.GetSingle.AddBaseClase(new EnemyBoom(this.X, this.Y,this.EnemyType));
                SingleClass.GetSingle.RemoveClass(this);
                switch (this.EnemyType)
                {
                    case 0:
                        //获得单例中记录玩家分数的属性
                        SingleClass.GetSingle.Score += 100;
                        break;
                    case 1:
                        SingleClass.GetSingle.Score += 200;
                        break;
                    case 2:
                        SingleClass.GetSingle.Score += 300;
                        break;
                }
            }
        }
    }
}
